import 'package:demo/config/app_config.dart';
import 'package:demo/views/extend/extend_space.dart';
import 'package:demo/views/extend/extend_video.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:demo/config/app_fonts.dart';
import 'package:demo/views/common/common_about_view.dart';
import 'package:demo/views/common/common_help_view.dart';
import 'package:demo/views/mine/mine_index_controller.dart';
import 'package:demo/views/mine/mine_safety_view.dart';
import 'package:demo/views/mine/mine_setting_view.dart';
import 'package:demo/tools/tools_storage.dart';
import 'package:demo/component/component_common.dart';
import 'package:demo/component/component_line.dart';

double _iconSize = 25;

// 我的页面
class MineIndexView extends GetView<MineIndexController> {
  const MineIndexView({super.key});

  @override
  Widget build(BuildContext context) {
    Get.lazyPut(() => MineIndexController());
    return Scaffold(
      appBar: AppBar(
        title: const Text('我的'),
      ),
      body: SingleChildScrollView(
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 4),
          child: Column(
            children: [
              Obx(
                () => _buildHeader(),
              ),
              ComponentCommon.border(),
              ComponentLineRow(
                "朋友圈",
                leading: Icon(
                  AppFonts.e61b,
                  color: const Color.fromARGB(255, 138, 7, 239),
                  size: _iconSize,
                ),
                onTap: () {
                  Get.toNamed(
                    ExtendSpace.routeName,
                  );
                },
              ),
              ComponentLineRow(
                "视频号",
                leading: Icon(
                  AppFonts.e64e,
                  color: const Color.fromARGB(255, 7, 239, 38),
                  size: _iconSize,
                ),
                onTap: () {
                  Get.toNamed(
                    ExtendVideo.routeName,
                  );
                },
                divider: false,
              ),
              ComponentCommon.border(),
              ComponentLineRow(
                "账号安全",
                leading: Icon(
                  AppFonts.e619,
                  color: const Color.fromARGB(255, 239, 139, 7),
                  size: _iconSize,
                ),
                onTap: () {
                  Get.toNamed(
                    MineSafetyView.routeName,
                  );
                },
              ),
              ComponentLineRow(
                "软件版本",
                leading: Icon(
                  AppFonts.e602,
                  color: const Color.fromARGB(255, 236, 42, 239),
                  size: _iconSize,
                ),
                value: '当前版本 V${AppConfig.version}',
                arrow: false,
              ),
              ComponentLineRow(
                "帮助中心",
                leading: Icon(
                  AppFonts.e63f,
                  color: Colors.blue,
                  size: _iconSize,
                ),
                onTap: () {
                  Get.toNamed(
                    CommonHelpView.routeName,
                  );
                },
              ),
              ComponentLineRow(
                "关于我们",
                leading: Icon(
                  AppFonts.e62e,
                  color: Colors.red,
                  size: _iconSize,
                ),
                onTap: () {
                  Get.toNamed(
                    CommonAboutView.routeName,
                  );
                },
              ),
            ],
          ),
        ),
      ),
    );
  }

  // 头像
  _buildHeader() {
    LocalUser localUser = controller.localUser.value;
    return GestureDetector(
      child: Container(
        padding: const EdgeInsets.only(
          left: 12,
          right: 6,
          top: 20,
          bottom: 20,
        ),
        color: Colors.white,
        child: Row(
          children: [
            Expanded(
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Padding(
                    padding: const EdgeInsets.only(right: 10),
                    child: ComponentCommon.showAvatar(
                      localUser.portrait,
                      size: 55,
                    ),
                  ),
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          localUser.nickname,
                          style: const TextStyle(
                            fontWeight: FontWeight.bold,
                          ),
                          overflow: TextOverflow.visible,
                        ),
                        Text('ID：${localUser.userNo}'),
                        Text(
                          '签名：${localUser.intro}',
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
            const Icon(Icons.qr_code),
            ComponentCommon.arrow(),
          ],
        ),
      ),
      onTap: () {
        Get.toNamed(MineSettingView.routeName);
      },
    );
  }
}
